﻿using Project.IData;
using System.Reflection;
using System.Configuration;

namespace Project.Data
{
    public partial class SimpleDataFactory
    {
		/// <summary>
		/// 获取ActionInfoData实例
		/// </summary>
		/// <returns></returns>
		public static IActionInfoData GetActionInfoData()
		{
			//暂时先使用固定的，将来会使用在Web.Config中配置的形式
			//string assemblyName = ConfigurationManager.AppSettings["assemblyName"].ToString();
			string assemblyName = "Project.Data";
            //string className = ConfigurationManager.AppSettings["className"].ToString()+".ActionInfoData";
			string className = "Project.Data.ActionInfoData";
			return GetInstance(assemblyName, className) as IActionInfoData;
		}
		/// <summary>
		/// 获取EmployeeData实例
		/// </summary>
		/// <returns></returns>
		public static IEmployeeData GetEmployeeData()
		{
			//暂时先使用固定的，将来会使用在Web.Config中配置的形式
			//string assemblyName = ConfigurationManager.AppSettings["assemblyName"].ToString();
			string assemblyName = "Project.Data";
            //string className = ConfigurationManager.AppSettings["className"].ToString()+".EmployeeData";
			string className = "Project.Data.EmployeeData";
			return GetInstance(assemblyName, className) as IEmployeeData;
		}
		/// <summary>
		/// 获取UserInfoData实例
		/// </summary>
		/// <returns></returns>
		public static IUserInfoData GetUserInfoData()
		{
			//暂时先使用固定的，将来会使用在Web.Config中配置的形式
			//string assemblyName = ConfigurationManager.AppSettings["assemblyName"].ToString();
			string assemblyName = "Project.Data";
            //string className = ConfigurationManager.AppSettings["className"].ToString()+".UserInfoData";
			string className = "Project.Data.UserInfoData";
			return GetInstance(assemblyName, className) as IUserInfoData;
		}
		/// <summary>
        /// 反射出相应的类对象，实例化返回
        /// </summary>
        /// <param name="assemblyName">程序集</param>
        /// <param name="className">类</param>
        /// <returns></returns>
        public static object GetInstance(string assemblyName,string className)
        {
            return Assembly.Load(assemblyName).CreateInstance(className, true);
        }
    }
}